package com.example.myapplication2;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.io.ObjectInputStream;
import java.util.List;

public class MyAdapter extends RecyclerView.Adapter <MyAdapter.MyViewHolder> {

    private final List image;
    private View itemview;
    private Context context;
    private List<String> data,mess,infor;

    public MyAdapter(Context context, List<String> data,List<String> mess,List<String> infor,List image) {

        this.context=context;
        this.data=data;
        this.mess=mess;
        this.infor=infor;
        this.image=image;

    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        itemview= LayoutInflater.from(context).inflate(R.layout.item,parent,false);
        MyViewHolder myViewHolder=new MyViewHolder(itemview);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        holder.textView.setText(data.get(position));
        holder.textView2.setText(mess.get(position));
        holder.textView3.setText(infor.get(position));
        holder.imageView.setImageResource((Integer) image.get(position));
        int adapterPosition = holder.getAdapterPosition();
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,MainActivity2.class);
                intent.putExtra("name", "xiao");
                context.startActivity(intent);

            }
        });
    }


    @Override
    public int getItemCount() {

        return data.size();
    }
    public class MyViewHolder extends RecyclerView.ViewHolder {
         TextView textView;
         TextView textView2;
         TextView textView3;
         ImageView imageView;

        public MyViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.textView1);
            textView2 = (TextView) itemView.findViewById(R.id.textView2);
            textView3 = (TextView) itemView.findViewById(R.id.textView3);
            imageView = itemView.findViewById(R.id.imageView1);
        }
    }
}
